﻿
using Microsoft.Practices.SharePoint.Common.Configuration;
using Microsoft.SharePoint.Administration;
using System.Collections.Generic;
using System.Linq;
namespace SharePoint.Contrib.ApplicationSettings
{
    internal class SPWebApplicationSettingsCollection : SettingsCollection
    {
        private SPWebApplication webapplication;

        public SPWebApplicationSettingsCollection(IPropertyBag properties, SPWebApplication webapplication)
            :base(properties)
        {
            this.webapplication = webapplication;
        }

        protected override IEnumerable<Setting> FindAll()
        {
            WebAppSettingStore ConfigurationStore = WebAppSettingStore.Load(webapplication);

            return (from setting in SPG.RemoveNamespaceFromKeys(ConfigurationStore.Settings)
                    select new Setting
                    {
                        Id = setting.Key,
                        Value = setting.Value
                    })
                   .ToArray();
        }
    }
}
